@echo off
chcp 65001 >nul
echo ========================================
echo Redeploy Smart Contract
echo ========================================
echo.

echo This will:
echo 1. Clean old artifacts
echo 2. Recompile contract
echo 3. Redeploy contract
echo 4. Update frontend ABI
echo.
pause

cd blockchain

echo [1/3] Cleaning old artifacts...
call npx hardhat clean
echo [OK] Clean complete
echo.

echo [2/3] Compiling contract...
call npx hardhat compile
if %ERRORLEVEL% neq 0 (
    echo [ERROR] Compilation failed
    pause
    exit /b 1
)
echo [OK] Compilation successful
echo.

echo [3/3] Deploying contract...
call npx hardhat run scripts/deploy.js --network localhost
if %ERRORLEVEL% neq 0 (
    echo [ERROR] Deployment failed
    echo.
    echo Make sure Hardhat node is running!
    echo Run 'npm run node' in blockchain folder first.
    pause
    exit /b 1
)
echo [OK] Deployment successful
echo.

echo ========================================
echo Contract redeployed successfully!
echo ========================================
echo.
echo ABI and contract address have been updated.
echo Please refresh your browser (Ctrl+F5)
echo.
pause

